package com.cd.common.domain;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
import java.util.List;

/**
 * @author admin
 * @description 用户信息表 ||  ||
 * @date 2024-03-25
 */
@Entity
@Data
@NoArgsConstructor
@AllArgsConstructor
@Table(name = "sys_user")
public class SysUser extends BaseDomain implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    //@Comment("用户ID")
    @Column(name = "user_id", nullable = false)
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long userId;

    //@Comment("部门ID")
    @Column(name = "dept_id")
    private Long deptId;

    //@Comment("用户账号")
    @Column(name = "user_name", nullable = false, unique = true)
    private String userName;

    //@Comment("用户昵称")
    @Column(name = "nick_name")
    private String nickName;

    //@Comment("用户类型（00系统用户）") 暂未使用
    @Column(name = "user_type")
    private String userType;

    //@Comment("用户邮箱")
    @Column(name = "email")
    private String email;

    //@Comment("手机号码")
    @Column(name = "phonenumber", unique = true)
    private String phonenumber;

    //@Comment("用户性别（0男 1女 2未知）")
    @Column(name = "sex")
    private String sex;

    //@Comment("头像地址")
    @Column(name = "avatar")
    private String avatar;

    //@Comment("密码")
    @Column(name = "password", nullable = false)
    private String password;

    //@Comment("帐号状态（0正常 1停用）")
    @Column(name = "status")
    private String status;

    //@Comment("删除标志（0代表存在 2代表删除）")
    @Column(name = "del_flag")
    private String delFlag;

    //@Comment("最后登录IP") 废弃 查记录
    @Column(name = "login_ip")
    private String loginIp;

    //@Comment("最后登录时间") 拟废弃 查登录记录
    @Column(name = "login_date")
    private Date loginDate;

    //@Comment("创建者")
    @Column(name = "create_by")
    private String createBy;

    //@Comment("创建时间")
    @Column(name = "create_time")
    private Date createTime;

    //@Comment("更新者")
    @Column(name = "update_by")
    private String updateBy;

    //@Comment("更新时间")
    @Column(name = "update_time")
    private Date updateTime;

    //@Comment("备注")
    @Column(name = "remark")
    private String remark;

    /**
     * 部门对象
     */
    @Transient
    private SysDept dept;

    /**
     * 角色对象
     */
    @Transient
    private List<SysRole> roles;

    @Transient
    /** 角色组 */
    private Long[] roleIds;
    @Transient
    /** 岗位组 */
    private Long[] postIds;

    //判断用户是否为admin用户
    public boolean isAdmin() {
        return isAdmin(this.userId);
    }

    public static boolean isAdmin(Long userId) {
        return userId != null && 1L == userId;
    }

    public SysUser(Long userId) {
        this.userId = userId;
    }

}

